﻿@using System.Reactive.Disposables
@using Blazor.Core;
@using Blazor.Localization
@using Blazor.Pages.UpdateSetting.Modals.Whitelist
@using Blazor.Services.Update
@using Blazor.ViewModels.UpdateSetting;
@using ReactiveUI
@inherits SoraniComponentBase<SingleSettingViewModel>

@if (ViewModel is not null)
{
    <Paragraph>
        <Descriptions Bordered Layout="DescriptionsLayout.Vertical">
            <DescriptionsItem Title="@_loc[UpdateSettingLocalization.RawResourceVersion]">
                @ViewModel.RawResourceVersion
            </DescriptionsItem>
            <DescriptionsItem Title="@_loc[UpdateSettingLocalization.DefaultResourceVersion]">
                @ViewModel.DefaultResourceVersion
            </DescriptionsItem>
            <DescriptionsItem Title="@_loc[UpdateSettingLocalization.VersionComment]">
                @ViewModel.ResourceVersionComment
            </DescriptionsItem>
            <DescriptionsItem Title="@_loc[UpdateSettingLocalization.ResourceUrl]">
                @ViewModel.ResourceUrl
                <Button Type="ButtonType.Link"
                        Icon="@IconType.Outline.Edit"
                        Loading="ViewModel.IsChangingResourceUrl"
                        OnClick="() => ViewModel.ChangeResourceUrl.Execute()"/>
            </DescriptionsItem>
        </Descriptions>
    </Paragraph>

    <AntList DataSource="@ViewModel.Whitelist">
        <Header>
            <Flex Justify="@FlexJustify.SpaceBetween" Gap="@FlexGap.Large">
                @_loc[UpdateSettingLocalization.Whitelist]
                <Space>
                    <SpaceItem>
                        <Button
                            Type="ButtonType.Primary"
                            Loading="ViewModel.IsAddingWhitelist"
                            OnClick="() => ViewModel.AddWhitelist.Execute().Subscribe()">@CommonLoc[CommonLocalization.Add]</Button>
                    </SpaceItem>
                    <SpaceItem>
                        <Button
                            Loading="ViewModel.IsClearingWhitelist"
                            OnClick="() => ViewModel.ClearWhitelist.Execute().Subscribe()">@CommonLoc[CommonLocalization.DeleteAll]</Button>
                    </SpaceItem>
                </Space>
            </Flex>
        </Header>
        <ChildContent Context="item">
            <ListItem>
                <WhitelistRow ViewModel="item"/>
            </ListItem>
        </ChildContent>
    </AntList>
}
else
{
    <Empty/>
}